[MINIOS] Fix the pagefault handler to detect recursive faults.
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Tue, 16 May 2006 15:34:27 +0000 (16:34 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Tue, 16 May 2006 15:34:27 +0000 (16:34 +0100)
Signed-off-by: Grzegorz Milos <gm281@cam.ac.uk>
extras/mini-os/console/console.c
extras/mini-os/traps.c

index 342a1edd4546df2851495e3f97a396e9ea502a89..29fdd99f3b0baf2fda801e311506737f19b14e72 100644 (file)
 #include <xen/io/console.h>
 
 
+/* Copies all print output to the Xen emergency console apart
+   of standard dom0 handled console */
+#define USE_XEN_CONSOLE
+
 /* Low level functions defined in xencons_ring.c */
 extern int xencons_ring_init(void);
 extern int xencons_ring_send(const char *data, unsigned len);
@@ -117,7 +121,9 @@ void print(int direct, const char *fmt, va_list args)
         (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(buf), buf);
         return;
     } else {
-        if(!console_initialised)
+#ifndef USE_XEN_CONSOLE
+    if(!console_initialised)
+#endif    
             (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(buf), buf);
         
         console_print(buf, strlen(buf));
@@ -128,7 +134,7 @@ void printk(const char *fmt, ...)
 {
     va_list       args;
     va_start(args, fmt);
-    print(1, fmt, args);
+    print(0, fmt, args);
     va_end(args);        
 }
 
index b6f366818e5070accd07492ff9ff7e71c921497e..43dca392686e7720f081770a0445378383741330 100644 (file)
@@ -120,9 +120,21 @@ void page_walk(unsigned long virt_address)
 #define read_cr2() \
         (HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].arch.cr2)
 
+static int handling_pg_fault = 0;
+
 void do_page_fault(struct pt_regs *regs, unsigned long error_code)
 {
     unsigned long addr = read_cr2();
+    /* If we are already handling a page fault, and got another one
+       that means we faulted in pagetable walk. Continuing here would cause
+       a recursive fault */       
+    if(handling_pg_fault) 
+    {
+        printk("Page fault in pagetable walk (access to invalid memory?).\n"); 
+        do_exit();
+    }
+    handling_pg_fault = 1;
+
 #if defined(__x86_64__)
     printk("Page fault at linear address %p, rip %p, code %lx\n",
            addr, regs->rip, error_code);
@@ -130,9 +142,12 @@ void do_page_fault(struct pt_regs *regs, unsigned long error_code)
     printk("Page fault at linear address %p, eip %p, code %lx\n",
            addr, regs->eip, error_code);
 #endif
+
     dump_regs(regs);
     page_walk(addr);
     do_exit();
+    /* We should never get here ... but still */
+    handling_pg_fault = 0;
 }
 
 void do_general_protection(struct pt_regs *regs, long error_code)